package Z.dailyExercise.March;

public class _剑指Offer66构建乘积数组 {

    /**
     * 借助两个数组 分别存储第i个元素 左右两侧 的积
     * @param a
     * @return
     */

    public int[] constructArr(int[] a) {
        if (a.length==0){
            return a;
        }

        int[] left = new int[a.length];
        int[] right = new int[a.length];

        left[0] = 1;
        right[a.length-1] = 1;

        for (int i = 1; i < left.length; i++) {
            left[i] = left[i-1] * a[i-1];

        }

        for (int i = right.length-2;i>=0;i--){
            right[i] = right[i+1] * a[i+1];
        }

        for (int i = 0; i < a.length; i++) {
            a[i] = left[i]* right[i];

        }
        return a;


    }
}
